package jxau.jwgl.web.controller;

import jxau.jwgl.commons.WebData;
import jxau.jwgl.commons.entity.Course;
import jxau.jwgl.commons.entity.CourseCategory;
import jxau.jwgl.commons.entity.User;
import jxau.jwgl.service.ChooseCourseSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * ChooseCourseController
 *
 * @author LongShu 2017/06/13
 */
@RestController
@RequestMapping("/chooseCourse")
public class ChooseCourseController extends BaseController {

    @Autowired
    private ChooseCourseSerivce chooseCourseSerivce;

    @GetMapping("/courseInfo")
    public Object courseInfo(HttpServletRequest request, CourseCategory category) {
        User loginUser = getLoginUser(request);

        List<Course> courseList = chooseCourseSerivce.courseInfo(loginUser.getUsername(), category);
        return WebData.newObj(courseList);
    }

    @PostMapping("/chooseCourse")
    public Object chooseCourse(HttpServletRequest request, Course course) {
        User loginUser = getLoginUser(request);

        String result = chooseCourseSerivce.chooseCourse(loginUser.getUsername(), course);
        return WebData.newMsg(result);
    }

}
